﻿<common:LayoutAwarePage x:Class="KouDai.Metro.MainPage"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:Share="using:KouDai.Share"
                        xmlns:common="using:KouDai.Metro.Common"
                        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                        xmlns:i="using:Windows.UI.Interactivity"
                        xmlns:local="using:KouDai.Metro.Views"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        x:Name="pageRoot"
                        DataContext="{Binding Main,
                                              Source={StaticResource Locator}}"
                        NavigationCacheMode="Required"
                        mc:Ignorable="d" FontFamily="Global User Interface">

    <Page.Resources>

        <!--  Collection of items displayed by this page  -->
        <CollectionViewSource x:Name="itemsViewSource" Source="{Binding Items}" />

        <DataTemplate x:Key="Honey250x250ItemTemplate">
            <Grid Width="250"
                  Height="250"
                  Margin="5,10"
                  HorizontalAlignment="Left">
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
                    <Image AutomationProperties.Name="{Binding Name}"
                           Source="{Binding ImageUrlForIphone}"
                           Stretch="UniformToFill" />
                </Border>
                <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                    <TextBlock Height="60"
                               Margin="15,0,15,0"
                               Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}"
                               Style="{StaticResource TitleTextStyle}"
                               Text="{Binding Name}" />

                </StackPanel>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ItemTemplate">
            <Grid Width="{Binding Width}" Height="{Binding Height}">
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
                    <Image Share:LowMemoryImageLoader.UriSource="{Binding ImageUrlForIphone}" Stretch="UniformToFill" />
                    <!--  Helper:LowMemoryImageLoader.UriSource="{Binding ImageUrlForIphone}"  -->
                </Border>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--  Horizontal scrolling grid used in most view states  -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton"
                    Click="GoBack"
                    IsEnabled="{Binding Frame.CanGoBack,
                                        ElementName=pageRoot}"
                    Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="pageTitle"
                       Grid.Column="1"
                       Margin="8,0,22,40"
                       IsHitTestVisible="false"
                       Style="{StaticResource PageHeaderTextStyle}"
                       Text="{StaticResource AppName}" />
        </Grid>

        <!--  Horizontal scrolling grid used in most view states  -->
        <GridView x:Name="itemGridView"
                  Grid.RowSpan="2"
                  AutomationProperties.AutomationId="ItemsGridView"
                  AutomationProperties.Name="Items"
                  IsItemClickEnabled="True"
                  IsSwipeEnabled="false"
                  ItemTemplate="{StaticResource Honey250x250ItemTemplate}"
                  ItemsSource="{Binding Items}"
                  Padding="116,136,116,46"
                  SelectionMode="None"
                  TabIndex="1">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="ItemClick">
                    <i:InvokeCommandAction Command="{Binding GoToDetailCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </GridView>

        <!--  Vertical scrolling list only used when snapped  -->
        <ListView x:Name="itemListView"
                  Grid.Row="1"
                  Margin="0,-10,0,0"
                  AutomationProperties.AutomationId="ItemsListView"
                  AutomationProperties.Name="Items"
                  IsItemClickEnabled="True"
                  IsSwipeEnabled="false"
                  ItemsSource="{Binding Items}"
                  Padding="10,0,0,60"
                  SelectionMode="None"
                  TabIndex="1"
                  Visibility="Collapsed">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Width="280"
                          Height="150"
                          Margin="0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="36*" />
                            <ColumnDefinition Width="35*" />
                        </Grid.ColumnDefinitions>
                        <Image Margin="0,0,11.464,0"
                               Source="{Binding ImageUrlForIphone}"
                               Stretch="UniformToFill" />
                        <TextBlock Grid.Column="1"
                                   Margin="0"
                                   Foreground="#FFD1EA35"
                                   Text="{Binding Name}"
                                   TextWrapping="Wrap" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <!--  Back button and page title  -->

        <VisualStateManager.VisualStateGroups>

            <!--  Visual states reflect the application's view state  -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape" />
                <VisualState x:Name="Filled" />

                <!--  The entire page respects the narrower 100-pixel margin convention for portrait  -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,136,86,56" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
